package com.freecloud.javabasics.design.single;

import com.freecloud.javabasics.design.entity.car.BMW;
import com.freecloud.javabasics.design.entity.car.Car;

/**
 * 单例：枚举式，可避免序列化和反射破坏
 * @Author: maomao
 * @Date: 2019-10-30 22:01
 */
public enum EnumSingleton {
    BMW(new BMW());

    private Car car;


    EnumSingleton(Car car){
        this.car = car;
    }

    Car getInstance(){
        return this.car;
    }



    public static void main(String[] args) {
        Car car1 = EnumSingleton.BMW.getInstance();
        Car car2 = EnumSingleton.BMW.getInstance();

        System.out.println(car1);
        System.out.println(car2);
    }
}
